home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / gdb-4.5 / dist / gdb / mips-xdep.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-03  |  4.2 KB  |  185 lines

  1. /* Low level MIPS interface to ptrace, for GDB when running under Unix.
  2.    Copyright 1988, 1989, 1991, 1992 Free Software Foundation, Inc.
  3.    Contributed by Alessandro Forin(af@cs.cmu.edu) at CMU
  4.    and by Per Bothner(bothner@cs.wisc.edu) at U.Wisconsin.
  5.  
  6. This file is part of GDB.
  7.  
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2 of the License, or
  11. (at your option) any later version.
  12.  
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with this program; if not, write to the Free Software
  20. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  21.  
  22. #include "defs.h"
  23. #ifdef sgi
  24. #include <sys/inst.h>
  25. #else
  26. #include <mips/inst.h>
  27. #endif
  28. #include "frame.h"
  29. #include "inferior.h"
  30. #include "symtab.h"
  31. #include "value.h"
  32.  
  33. #ifdef USG
  34. #include <sys/types.h>
  35. #endif
  36.  
  37. #include <sys/param.h>
  38. #include <sys/dir.h>
  39. #include <signal.h>
  40. #include <sys/ioctl.h>
  41. /* #include <fcntl.h>  Can we live without this?  */
  42.  
  43. #include "gdbcore.h"
  44.  
  45. #include <sys/user.h>        /* After a.out.h  */
  46. #include <sys/file.h>
  47. #include <sys/stat.h>
  48.  
  49. /* For now we stub this out; sgi format is super-hairy (and completely
  50.    different in the new release) */
  51.  
  52. #ifdef sgi
  53. void
  54. fetch_core_registers ()
  55. {
  56.   return;
  57. }
  58.  
  59. /* ARGSUSED */
  60. void
  61. fetch_inferior_registers (regno)
  62.      int regno;
  63. {
  64.   return;
  65. }
  66.  
  67. /* ARGSUSED */
  68. void
  69. store_inferior_registers (regno)
  70.      int regno;
  71. {
  72.   return;
  73. }
  74.  
  75.  
  76. #else
  77.  
  78. /* Map gdb internal register number to ptrace address. */
  79.  
  80. #define REGISTER_PTRACE_ADDR(regno) \
  81.  (regno < 32 ? regno         \
  82.   : regno == PC_REGNUM ? 96    \
  83.   : regno == CAUSE_REGNUM ? 97    \
  84.   : regno == HI_REGNUM ? 98    \
  85.   : regno == LO_REGNUM ? 99    \
  86.   : regno == FCRCS_REGNUM ? 100    \
  87.   : regno == FCRIR_REGNUM ? 101    \
  88.   : regno >= FP0_REGNUM ? regno - (FP0_REGNUM-32)\
  89.   : 0)
  90.  
  91. /* Get all registers from the inferior */
  92.  
  93. void
  94. fetch_inferior_registers (regno)
  95.      int regno;
  96. {
  97.   register unsigned int regaddr;
  98.   char buf[MAX_REGISTER_RAW_SIZE];
  99.   register int i;
  100.  
  101.   registers_fetched ();
  102.  
  103.   for (regno = 1; regno < NUM_REGS; regno++)
  104.     {
  105.       regaddr = REGISTER_PTRACE_ADDR (regno);
  106.       for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (int))
  107.      {
  108.        *(int *) &buf[i] = ptrace (3, inferior_pid, regaddr, 0);
  109.        regaddr += sizeof (int);
  110.      }
  111.       supply_register (regno, buf);
  112.     }
  113. }
  114.  
  115. /* Store our register values back into the inferior.
  116.    If REGNO is -1, do this for all registers.
  117.    Otherwise, REGNO specifies which register (so we can save time).  */
  118.  
  119. void
  120. store_inferior_registers (regno)
  121.      int regno;
  122.  {
  123.   register unsigned int regaddr;
  124.   char buf[80];
  125.  
  126.   if (regno == 0)
  127.     return;
  128.  
  129.   if (regno > 0)
  130.     {
  131.       regaddr = REGISTER_PTRACE_ADDR (regno);
  132.       errno = 0;
  133.       ptrace (6, inferior_pid, regaddr, read_register (regno));
  134.       if (errno != 0)
  135.     {
  136.       sprintf (buf, "writing register number %d", regno);
  137.       perror_with_name (buf);
  138.     }
  139.     }
  140.   else
  141.     {
  142.       for (regno = 0; regno < NUM_REGS; regno++)
  143.     {
  144.       if (regno == ZERO_REGNUM || regno == PS_REGNUM
  145.           || regno == BADVADDR_REGNUM || regno == CAUSE_REGNUM
  146.           || regno == FCRIR_REGNUM || regno == FP_REGNUM
  147.           || (regno >= FIRST_EMBED_REGNUM && regno <= LAST_EMBED_REGNUM))
  148.         continue;
  149.       regaddr = register_addr (regno, 1);
  150.       errno = 0;
  151.       ptrace (6, inferior_pid, regaddr, read_register (regno));
  152.       if (errno != 0)
  153.         {
  154.           sprintf (buf, "writing all regs, number %d", regno);
  155.           perror_with_name (buf);
  156.         }
  157.     }
  158.     }
  159. }
  160.  
  161. #endif /* sgi */
  162.  
  163. #if 0
  164. void
  165. fetch_core_registers ()
  166. {
  167.   register int regno;
  168.   int val;
  169.  
  170.   for (regno = 1; regno < NUM_REGS; regno++) {
  171.     char buf[MAX_REGISTER_RAW_SIZE];
  172.  
  173.     val = bfd_seek (core_bfd, register_addr (regno, 0));
  174.     if (val < 0 || (val = bfd_read (core_bfd, buf, sizeof buf)) < 0) {
  175.       char buffer[50];
  176.       strcpy (buffer, "Reading register ");
  177.       strcat (buffer, reg_names[regno]);
  178.  
  179.       perror_with_name (buffer);
  180.     }
  181.     supply_register (regno, buf);
  182.   }
  183. }
  184. #endif /* 0 */
  185.